package com.gxar.quick.ar.server.base.common.enums;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author linsy
 * @version 1.0
 * @created 2023/11/9 09:53
 */
public enum UserWorksSourceEnum {
    SHARE(0, "share", "分享"),
    SELF(1, "self", "自制"),
    PLAZA(2, "plaza", "广场");

    private final Integer code;
    private final String name;
    private final String desc;

    /**
     * 根据名称获取枚举
     *
     * @param name 名称
     * @return 枚举
     */
    public static UserWorksSourceEnum getByName(String name) {
        UserWorksSourceEnum userWorksSourceEnum = Arrays.stream(UserWorksSourceEnum.values()).filter(e -> e.getName().equals(name)).findFirst().orElse(null);
        if (Objects.nonNull(userWorksSourceEnum)) {
            return userWorksSourceEnum;
        }
        return null;
    }

    /**
     * 根据code查询
     *
     * @param code code
     * @return 响应
     */
    public static UserWorksSourceEnum getByCode(Integer code) {
        UserWorksSourceEnum userWorksSourceEnum = Arrays.stream(UserWorksSourceEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        if (Objects.nonNull(userWorksSourceEnum)) {
            return userWorksSourceEnum;
        }
        return null;
    }

    UserWorksSourceEnum(Integer code, String name, String desc) {
        this.code = code;
        this.name = name;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getDesc() {
        return desc;
    }
}
